package scsc.pub.process.receivefile;

import java.util.ArrayList;

import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

import scsc.pm.DispatchPm;
import scsc.pm.ReceiveFilePm;
import scsc.pub.db.DBManage;
import scsc.pub.exception.UnifyUserException;
import scsc.web.process.data.DispatchData;
import scsc.web.process.data.ReceiveFileData;

public class PigeOnHoleAction implements ActionHandler {

	public void execute(ExecutionContext executionContext) throws Exception {
		// TODO Auto-generated method stub
		ReceiveFileData data = new ReceiveFileData();
		ReceiveFilePm receiveFile = new ReceiveFilePm();
		DBManage dbmanage = new DBManage();
		try {
			data.setProcessInstanceId(executionContext.getProcessInstance()
					.getId());
			ArrayList al = receiveFile.selectReceiveFiles(dbmanage, data);
			dbmanage.begin();
			if (al != null && al.size() == 1) {
				ReceiveFileData receiveFileData = (ReceiveFileData) al.get(0);
				receiveFileData.setState("1");
				receiveFile.modifyReceiveFile(dbmanage, receiveFileData);
			}
			dbmanage.commit();
			dbmanage.close();
		} catch (UnifyUserException e) {
			dbmanage.rollback();
			dbmanage.close();
		}
	}

}
